import type { TableData } from "@@/apis/tables/type.ts"
import type * as Auth from "./type.ts"
import { request } from "@/http/axios.ts"
import {
  askQuestionRequestData,
  askQuestionResponseData,
  getCardDetailListResponseData,
  wechatPayResponseData
} from "./type.ts";
import {Builtin, RefUnwrapBailTypes, UnwrapRefSimple} from "@vue/reactivity";
import {UnwrapRef} from "vue";
import {RouteParamValue} from "vue-router";

export function articleApi(data: { page: number, type: string, tag_ids: string, limit: number }) {
  return request<Auth.articleResponseData>({
    url: "articlelist",
    method: "post",
    data
  })
}

// getCirclePostList
export function getCirclePostListApi(data: { page: number, limit: number }) {
  return request<Auth.articleResponseData>({
    url: "circlepostlist",
    method: "post",
    data
  })
}

// getCirclePostDetailApi
export function getCirclePostDetailApi(data: { id: number }) {
  return request<Auth.articleResponseData>({
    url: "circlepost",
    method: "post",
    data
  })
}
// 获取首页的4条置顶信息列表
export function getIndexFourBannerApi(data: { page: number, limit: number , area: number }) {
  return request<Auth.articleResponseData>({
    url: "indexfourbanner",
    method: "post",
    data
  })
}
// getNewsFourBannerApi
export function getIndexFourNewsBannerApi(data: { page: number, limit: number , area: number }) {
  return request<Auth.articleResponseData>({
    url: "indexfourbanner",
    method: "post",
    data
  })
}
// 获取首页的4条置顶信息列表
export function getIndexFourNewsListApi(data: { page: number, limit: number }) {
  return request<Auth.articleResponseData>({
    url: "getindexfourlistall",
    method: "post",
    data
  })
}
// getIndexFourBannerApi

// 获取资讯页面的标签列表
export function getTagListApi(data: { page: number, type: string, limit: number }) {
  return request<Auth.articleResponseData>({
    url: "taglist",
    method: "post",
    data
  })
}
// getCarddetaillist
export function getCardDetailListApi(data: { page: number, type: string, limit: number }) {
  return request<Auth.getCardDetailListResponseData>({
    url: "carddetaillist",
    method: "post",
    data
  })
}
export function articleDetailApi(data: { id: number }) {
  return request<Auth.articleDetailResponseData>({
    url: "articledetail",
    method: "post",
    data
  })
}

export function askQuestionApi(data: { user_id: number, content: string }) {
  return request<Auth.askQuestionResponseData>({
    url: "questionadd",
    method: "post",
    data
  })
}

// getHistoryQuestionListApi
export function getHistoryQuestionListApi(data: { page: number, type: string, limit: number }) {
  return request<Auth.getHistoryQuestionListResponseData>({
    url: "questionlist",
    method: "post",
    data
  })
}
export type TableResponseData = ApiResponseData<{
  list: TableData[]
  total: number
}>

// 问答列表
export function getQuestionListApi(data: { id: number }) {
  return request<Auth.getQuestionListResponseData>({
    url: "questionlist",
    method: "post",
    data
  })
}

// 课程列表 courselist
export function getCourseListApi(data: { page: number, type: string, limit: number }) {
  return request<Auth.courseListResponseData>({
    url: "courselist",
    method: "post",
    data
  })
}

// 刷一刷课程列表 courselist。去除已经访问过的课程列表
export function getCourseListRefreshApi(data: { page: number, type: string, limit: number }) {
  return request<Auth.courseListResponseData>({
    url: "refreshcourselistall",
    method: "post",
    data
  })
}
// getCardDetailDetailApi
export function getCardDetailDetailApi(data: { id: string extends (Builtin | Ref | RefUnwrapBailTypes[keyof RefUnwrapBailTypes] | { "[RawSymbol]"?: true }) ? string : (string extends Map<infer K, infer V> ? (Map<K, UnwrapRefSimple<V>> & UnwrapRef<Omit<string, keyof Map<any, any>>>) : (string extends WeakMap<infer K, infer V> ? (WeakMap<K, UnwrapRefSimple<V>> & UnwrapRef<Omit<string, keyof WeakMap<any, any>>>) : (string extends Set<infer V> ? (Set<UnwrapRefSimple<V>> & UnwrapRef<Omit<string, keyof Set<any>>>) : (string extends WeakSet<infer V> ? (WeakSet<UnwrapRefSimple<V>> & UnwrapRef<Omit<string, keyof WeakSet<any>>>) : (string extends ReadonlyArray<any> ? { [K in keyof string]: UnwrapRefSimple<string[K]> } : (string extends (object & { "[ShallowReactiveMarker]"?: never }) ? { [P in keyof string]: P extends symbol ? string[P] : UnwrapRef<string[P]> } : string)))))) | Array<UnwrapRefSimple<RouteParamValue>> }) {
  return request<Auth.getCardDetailDetailResponseData>({
    url: "carddetaildetail",
    method: "post",
    data
  })
}

// 课程详情
export function getCourseDetailApi(data: { id: number, user_id: number}) {
  return request<Auth.getCardDetailDetailResponseData>({
    url: "coursedetail",
    method: "post",
    data
  })
}


// 发送评论
export function sendCommentApi(data: { source_id: number, contents: string, user_id: number, ctype: number, img_list: string, action: number }) {
  return request<Auth.sendCommentResponseData>({
    url: "commentadd",
    method: "post",
    data
  })
}

// 回复评论
export function sendReplyCommentApi(data: { source_id: number, contents: string, user_id: number, ctype: number, img_list: string, action: number, parent_id: number }) {
  return request<Auth.sendCommentResponseData>({
    url: "commentreplyadd",
    method: "post",
    data
  })
}
// 点赞【对课程，要素卡点赞】
export function doLikeApi(data: { source_id: number, user_id: number, ctype: number, action: number }) {
  return request<Auth.doLikeResponseData>({
    url: "followadd",
    method: "post",
    data
  })
}

// action :10
export function doUnLikeApi (data: { id: number, user_id: number, ctype: number, action: number }) {
  return request<Auth.doLikeResponseData>({
    url: "followdeletebyuser",
    method: "post",
    data
  })
}
// 收藏【对课程，要素卡收藏】 doCollectApi
export function doCollectApi(data: { d: number, user_id: number, ctype: number, action: number }) {
  return request<Auth.doCollectResponseData>({
    url: "followadd",
    method: "post",
    data
  })
}

// makecardadd
export function doMakeCardApi(data: { id: number, user_id: number, card_type: number, action: number }) {
  return request<Auth.doCollectResponseData>({
    url: "makecardadd",
    method: "post",
    data
  })
}
export function addOrderApi(data: { user_id: number, account: number, pay_info: string}) {
  return request<Auth.addOrderResponseData>({
    url: "rechargeadd",
    method: "post",
    data
  })
}

export function wechatPayApi(data: { id: number, account: number, pay_type: number, single_pay: number,  client_type: number,  accept_name: string, }) {
  return request<Auth.wechatPayResponseData>({
    url: "rechargepay",
    method: "post",
    data
  })
}

export function wechatPayApi2(data: { order_id: number}) {
  return request<Auth.wechatPayResponseData>({
    url: "rechargepay",
    method: "post",
    data
  })
}

export function getWxStatusApi() {
  return request<Auth.getWxStatusResponseData>({
    url: "getwxstatus",
    method: "post",
  })
}

export function getWxQrCodeApi() {
  return request<Auth.getWxQrCodeResponseData>({
    url: "getwxqrcode",
    method: "post",
  })
}

export function getWechatLoginUrl() {
  return request<Auth.getWechatLoginUrlResponseData>({
    url: "getwechatloginurl",
    method: "post",
  })
}

// id
export function checkOrderDetailApi(data: { id: number}) {
  return request<Auth.checkOrderDetailResponseData>({
    url: "rechargedetail",
    method: "post",
    data
  })
}

// wechatScanLogin
export function wechatScanLoginApi(data: { code: string}) {
  return request<Auth.wechatScanLoginResponseData>({
    url: "wechatscanlogin",
    method: "post",
    data
  })
}

// getUserInfoApi
export function getUserInfoApi(data: { uid: number}) {
  return request<Auth.getUserInfoResponseData>({
    url: "myinfo",
    method: "post",
    data
  })
}

export interface personalRequestData2 {
  username: string
  mobile: string
  birthday: any
  sex: number
  uid: number
  head_ico: string
  hangye: number
  zhicheng: number
  job: number
  edu: number
  email: string
}
// saveUserDataApi
export function saveUserDataApi(data: personalRequestData2) {
  return request<Auth.saveUserDataResponseData>({
    url: "myinfoupdate",
    method: "post",
    data
  })
}
// myinfoupdate
export function myInfoUpdateApi(data: { id: number, img: string,}) {
  return request<Auth.myinfoupdateResponseData>({
    url: "myinfoupdate",
    method: "post",
    data
  })
}
// saveUserAvatarApi
export function saveUserAvatarApi(data: { id: number, img: string}) {
  return request<Auth.saveUserAvatarResponseData>({
    url: "setavatar",
    method: "post",
    data
  })
}

//getUserFollowListApi
export function getUserFollowListApi(data: { uid: number, page: number, limit: number, action: number, ctype: number}) {
  return request<Auth.getUserFollowListResponseData>({
    url: "userhistorylist",
    method: "post",
    data
  })
}

// getUserCommentListApi
export function getUserCommentListApi(data: { uid: number, page: number, limit: number}) {
  return request<Auth.getUserCommentListResponseData>({
    url: "commentlist",
    method: "post",
    data
  })
}

// getUserPaymentListApi
export function getUserPaymentListApi(data: { uid: number, status: number, page: number, limit: number}) {
  return request<Auth.getUserPaymentListResponseData>({
    url: "rechargelist",
    method: "post",
    data
  })
}

// getUserNoticeListApi
export function getUserNoticeListApi(data: { uid: number, page: number, limit: number}) {
  return request<Auth.getUserNoticeListResponseData>({
    url: "mynoticelist",
    method: "post",
    data
  })
}

// 学友圈推荐的5条评论信息
export function getCirclePostListByPageApi(data: { uid: number, page: number, limit: number,reply_Page: number, reply_limit: number}) {
  return request<Auth.getCirclePostListResponseData>({
    url: "circlepostlistByPage",
    method: "post",
    data
  })
}

// 学友圈刷一刷，4条记录
export function getCirclePostListRefreshApi(data: { uid: number, page: number, limit: number}) {
  return request<Auth.getCirclePostListResponseData>({
    url: "refreshcirclepostlist",
    method: "post",
    data
  })
}

//
export function getCirclePostReplyAllApi(data: { uid: number, page: number, limit: number,comment_id: number}) {
  return request<Auth.getCirclePostListResponseData>({
    url: "circlepostreplyall",
    method: "post",
    data
  })
}
